import akshare as ak

# https://www.akshare.xyz/data/stock/stock.html#id20 接口参考地址

# print(ak.stock_zh_a_spot_em()) # 获取东方财富网-沪深京 A 股-实时行情

import time


class TimeUtils:
    """
        返回今天的日期，示例：20240111
    """

    @staticmethod
    def today():
        today = time.localtime()  # 获取今天的日期
        date_str = time.strftime("%Y%m%d", today)  # 格式化，示例：20240111
        return date_str

    """
        返回k天前的日期，示例：20240104
    """

    @staticmethod
    def before_k_day(k: int = 7):
        t = time.time() - 86400 * k  # 计算k天前的时间戳
        old = time.localtime(t)  # 获取七天前的日期
        date_str = time.strftime("%Y%m%d", old)  # 格式化，示例：20240104
        return date_str


if __name__ == '__main__':
    # print(TimeUtils.today())
    # print(TimeUtils.before_k_day(7))
    code = "600519"  # 输入股票代码
    print(ak.stock_zh_a_hist(symbol=code, period="daily", start_date=TimeUtils.before_k_day(1),
                             end_date=TimeUtils.today())["收盘"][0])
